package com.yanqu.road.server.cmd.activity.oldplayerreturn;

import com.yanqu.road.pb.activity.OldPlayerReturnProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.oldplayerreturn.OldPlayerReturnModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/12/13 20:04
 */
@Cmd(code = GameProtocol.S_OLD_PLAYER_RETURN_GET_EVENT_REWARD, desc = "领取事件奖励")
public class GetEventRewardCmd extends AbstractCommand {
    private int choose;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        OldPlayerReturnProto.GetOldPlayerReturnEventRewardReqMsg msg = OldPlayerReturnProto.GetOldPlayerReturnEventRewardReqMsg.parseFrom(packet.getBytes());
        choose = msg.getChoose();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(OldPlayerReturnModule.class).getEventReward(choose);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            OldPlayerReturnProto.GetOldPlayerReturnEventRewardRespMsg.Builder respMsg = OldPlayerReturnProto.GetOldPlayerReturnEventRewardRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_OLD_PLAYER_RETURN_GET_EVENT_REWARD, respMsg);
        }
    }
}
